#include "tscprinter.h"
#include <QDebug>
#include <QMessageBox>

TscPrinter::TscPrinter(QObject *parent)
    : QObject{parent}
{
    tscdll.setFileName("TSCLIB.dll");
    isSuccess = false;
    if(tscdll.load()) {
        about=(TSCabout)tscdll.resolve("about");    //add about() function
        openport=(TSCopenport)tscdll.resolve("openport");    //add about() function
        closeport=(TSCcloseport)tscdll.resolve("closeport");    //add closeport() function
        sendcommand=(TSCsendcommand)tscdll.resolve("sendcommand");
        usbprintername =(TSCusbprintername)tscdll.resolve("usbprintername");

        isSuccess = true;

        auto name = UsbPrinterName();
        qDebug() << name;
    } else {
        QLibrary a("TSCLIB.dll");
        if (a.load()) {
            qDebug() << "读取e:\\TSCLIB.dll成功。";
        } else {
            qDebug() << "读取e:\\TSCLIB.dll失败。";
        }

        qDebug() << "读取TSCLIB.dll失败。";
        QMessageBox::warning(nullptr, "应用初始化错误", "读取打印机驱动TSCLIB.dll失败。", QMessageBox::Ok);
    }
}

int TscPrinter::About(){
    if (!isSuccess) return 0;
    return 0;
}

int TscPrinter::OpenPort(){
    if (!isSuccess) return 0;
    return 0;
}

int TscPrinter::ClosePort(){
    if (!isSuccess) return 0;
    return 0;
}

int TscPrinter::SendCommand(){
    if (!isSuccess) return 0;
    return 0;
}

QString TscPrinter::UsbPrinterName(){
    if (!isSuccess) return "";
    char* res = usbprintername();
    return QString(res);
}
